// pages/order/order.js
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';


Page({

  /**
   * 页面的初始数据
   */
  data: {
    cartList:[],
    totalPrice:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getCartList()

  },
  getCartList(){

    let str = wx.getStorageSync('user')
    if(str){
      let user = JSON.parse(str)
      wx.request({
        url: 'http://localhost:3000/api/cartlist?uid='+user.uid,
        success: res => {
          let list = res.data.list

          this.setData({
            cartList:list
          })
          this.calTotalPrice()
        }
      })
      
    }

  },
    // 计算总价
    calTotalPrice(){
      let count = 0;
      let list = this.data.cartList;
      list.forEach(item=>{

          count += item.price * item.num

      })
      this.setData({
        totalPrice:count
      })
    },
    onClickButton(){
      Toast.success('成功支付');
    }

})